//
//  CustomTopBar.swift
//  MyCloset
//
//  Created by 牟好好 on 2024/11/19.
//

import SwiftUI

struct CustomTopBar: View {
    @Binding var selectedTab: String
    
    var body: some View {
        HStack(spacing: 20) {
            ForEach(["plus.app", "trash.square"], id: \.self) { tab in
                HStack {
                    Image(systemName: selectedTab == tab ? tab + ".fill" : tab)
                        .font(.title2)
                    
                    if selectedTab == tab {
                        Text(tab == "plus.app" ? "新增搭配" : "删除搭配")
                    }
                }
                .padding()
                .bold()
                .background {
                    Rectangle()
                        .fill(selectedTab == tab ? .blue : .gray.opacity(0.3))
                }
                // 使圆角更平滑
                .clipShape(.rect(cornerRadius: 20, style: .continuous))
                .cornerRadius(12)
                .foregroundStyle(selectedTab == tab ? .white : .gray)
                .onTapGesture {
                    withAnimation(.linear(duration: 0.5)) {
                        selectedTab = tab
                    }
                }
            }
        }
    }
}

#Preview {
    CustomTopBar(selectedTab: .constant("plus.app"))
}
